#include "StdAfx.h"
#include "CFTransDBCenter.h"
#include "SNPublicFuc.h"
#include <Shlwapi.h>

CFTransDBCenter::CFTransDBCenter(void)
{
}

CFTransDBCenter::~CFTransDBCenter(void)
{
}

CFTransDBCenter* CFTransDBCenter::m_pInstance = NULL;


CFTransDBCenter* CFTransDBCenter::GetInstance(void)
{
	if (NULL == m_pInstance)
		m_pInstance = new CFTransDBCenter();
	return m_pInstance;

}

void CFTransDBCenter::ReleaseInstance()
{
	if (m_pInstance)
	{
		m_pInstance->UninitDataCenter();
		delete m_pInstance;
	}
}

BOOL CFTransDBCenter::InitDataCenter()
{
	m_sDbPathName = CPublicFuc::GetUserAppPath();
	m_sDbPathName += _T("\\WTPFileTrancefer");
	if(!::PathFileExists(m_sDbPathName))
		::CreateDirectory(m_sDbPathName, NULL);

	m_sDbPathName += DEF_DB_NAME;
	USES_CONVERSION;
	char* lpDbName = W2A(m_sDbPathName);

	return m_oSqlliteHelper.OpenDb(lpDbName);
}

BOOL	CFTransDBCenter::UninitDataCenter()
{
	m_oSqlliteHelper.CloseDb();
	return TRUE;
}

BOOL	CFTransDBCenter::LoadFileInfo(std::vector<S_FileDBInfo*>& apFileInfo)
{
	return m_oSqlliteHelper.LoadFileInfo(apFileInfo);
}

BOOL	CFTransDBCenter::AddFileInfo(S_FileDBInfo* apFileDbInfo)
{
	return m_oSqlliteHelper.AddFileInfo(apFileDbInfo);
}


BOOL	CFTransDBCenter::UpdateFileInfo(S_FileDBInfo* apFileDbInfo)
{

	return m_oSqlliteHelper.UpdateFileInfo(apFileDbInfo);
}

BOOL	CFTransDBCenter::DeleteFileInfo(S_FileDBInfo* apFileDbInfo)
{
	return m_oSqlliteHelper.DeleteFileInfo(apFileDbInfo);
}